#!/bin/sh
######################
#
# It's nesseray that to run top50 before this module 
#
######################
FOLDER=SMW

mv *.data ${FOLDER}
mv all.array.top50 ${FOLDER}
cd ${FOLDER}
filenames=`wc -l all.array.top50 | awk '{print $1}'`

# generate SWM.stock.sh
echo '#!/bin/sh' > ${FOLDER}.stock.sh
cat all.array.top50 >> ${FOLDER}.stock.sh
cat ${FOLDER}.tample.sh >> ${FOLDER}.stock.sh
#########
echo "i=0
while [ \$i -le $((filenames-1)) ]"  >> ${FOLDER}.stock.sh
#########
cat ${FOLDER}.tample.1.sh >> ${FOLDER}.stock.sh

# generate convert_stock_to_SMW.sh
echo '#!/bin/sh' > convert_stock_to_SMW.sh
cat all.array.top50 >> convert_stock_to_SMW.sh

#####
echo "i=0
while [ \$i -le $((filenames-1)) ]" >> convert_stock_to_SMW.sh
#####
cat convert_stock_to_SMW.tample.sh >> convert_stock_to_SMW.sh

chmod a+x *.sh
./${FOLDER}.sh